package com.ai.trickycards.ui.dialog

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.View.OnClickListener
import androidx.annotation.DrawableRes
import androidx.core.content.ContextCompat
import com.ai.trickycards.R
import com.ai.trickycards.databinding.DialogGameModeBinding
import com.ai.trickycards.entity.enumeration.GameMode

class GameModeDialog(
    context: Context,
    val gameMode: GameMode,
    @DrawableRes private val modeCardResId: Int,
    private val clickListener: (GameModeDialog) -> Unit
) : Dialog(context) {

    private val binding by lazy {
        DialogGameModeBinding.inflate(layoutInflater)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(binding.root)
        window?.let {
            it.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
            val displayMetrics = context.resources.displayMetrics
            it.attributes.width = (displayMetrics.widthPixels - 80 * displayMetrics.density).toInt()
        }

        binding.tvTitle.text = gameMode.title
        binding.tvPlayersValue.text = "${gameMode.playerCount}"
        binding.tvLivesValue.text = "${gameMode.lives}"
        binding.ivModeRoyalCard.setImageResource(modeCardResId)
        binding.tvLetter.text = gameMode.letter
        binding.tvScore.text = "${gameMode.score}"
        binding.llOption.setOnClickListener {
            clickListener.invoke(this)
        }
    }
}